<template>
    <section class="secretaryTaskRelease">
        <div v-loading="load" element-loading-text="任务发布中，请稍后" element-loading-background="rgba(0, 0, 0, 0.3)">
            <div class="topCard">
                <el-card class="titleCard">
                    <p v-if="releaseType==='基本信息更新'" class="release-title">发布任务</p>
                    <p v-else class="release-title">任务发布</p>
                    <span class="release-title-detail">任务基本信息</span>
                </el-card>
            </div>
            <el-card class="cardHeight">
                <el-form :inline="true" :model="form" ref="form" class="release-form" label-width="100px" :rules="rules">
                    <el-row class="firstRow">
                        <el-col :span="12">
                            <el-form-item label="任务名称" prop="name">
                                <el-input v-model="form.name"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col  :span="12">
                            <el-form-item label="截止日期" prop="endTime">
                                <el-date-picker v-model="form.endTime" type="date" placeholder="选择截止日期" value-format="yyyy-MM-dd" :picker-options="pickerOption">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="任务类型" prop="type">
                                <el-select v-model="form.type" :disabled="disabled">
                                    <el-option v-for="item in typeList" :value="item.value" :label="item.label" :key="item.value" ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <div v-if="form.type === '日常工作考核'">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="任务年度" prop="taskYear">
                                    <el-date-picker
                                        v-model="form.taskYear"
                                        type="year"
                                        placeholder="请选择任务年度">
                                    </el-date-picker>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="任务季度" prop="taskQuarter">
                                    <el-select v-model="form.taskQuarter">
                                        <el-option value="第一季度" label="第一季度" key="第一季度"></el-option>
                                        <el-option value="第二季度" label="第二季度" key="第二季度"></el-option>
                                        <el-option value="第三季度" label="第三季度" key="第三季度"></el-option>
                                        <el-option value="第四季度" label="第四季度" key="第四季度"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </div>
                    <el-row>
                        <el-col>
                            <el-form-item label="工作内容" prop="content">
                                <el-input v-model="form.content" type="textarea" style="width:340px" :rows="4"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <el-row>
                        <el-form-item label=" ">
                            <el-button type="primary" @click="submit('form')" size="medium" class="btnReleave">
                                <icon name="release" scale="2" class="release-icon" ></icon>
                                <span>发 布</span>
                            </el-button>
                            <el-button type="warning" @click="reWrite('form')" size="medium" class="btn_reset">
                                <icon name="reWrite" scale="2" class="release-icon"></icon>
                                <span>重 置</span>
                            </el-button>
                        </el-form-item>
                    </el-row>
                </el-form>
            </el-card>
        </div>
    </section>
</template>

<script>
    export default {
        name: "SecretaryTaskRelease",
        props:{
            releaseType:{
                type:String,
            }
        },
        data(){
            return{
                load:false,
                form:{},
                rules:{
                    name: [
                        { required: true, message: '请输入标题', trigger: 'blur' }
                    ],
                    type: [
                        { required: true, message: '请选择类型', trigger: 'blur' }
                    ],
                    endTime: [
                        { required: true, message: '请选择截止时间', trigger: 'blur'}
                    ],
                    taskYear:[
                        { required: true, message: '请选择任务年度', trigger: 'blur'}
                    ],
                    taskQuarter:[
                        { required: true, message: '请选择任务季度', trigger: 'blur'}
                    ]
                },
                pickerOption: {
                    disabledDate(time) {
                        return time.getTime() < Date.now() - 8.64e7;
                    },
                },
                typeList:[
                    {
                        label:"基本信息更新",
                        value:"基本信息更新"
                    },
                    {
                        label:"考核指标内容制定",
                        value:"考核指标内容制定"
                    },
                    {
                        label:"考核实施",
                        value:"考核实施"
                    },
                    {
                        label:"职级评定",
                        value:"职级评定"
                    },
                    {
                        label:"日常工作考核",
                        value:"日常工作考核"
                    },
                    {
                        label:"村干部信息更新",
                        value:"村干部信息更新"
                    }
                ],
                checkTypeList:[
                    {
                        label:"考核实施",
                        value:"考核实施"
                    },
                    {
                        label:"日常工作考核",
                        value:"日常工作考核"
                    }
                ],
                disabled:false,
            }
        },
        methods:{
            submit(form){
                this.$refs[form].validate((valid) => {
                    if (valid) {
                        this.load = true;
                        if(this.releaseType == '村干部信息更新'){
                            this.form.taskModule = "IN_SECRETARY";
                        }else {
                            this.form.taskModule = "SECRETARY";
                        }
                        this.$http('POST', `/identity/cadreTask/`, this.form).then((data) => {
                            this.form = {};
                            this.initType();
                            this.$refs[form].resetFields();
                            this.load = false;
                            this.$emit('releaseSuccess');
                        }).catch(()=>{
                            this.form = {};
                            this.initType();
                            this.$refs[form].resetFields();
                            this.load = false;
                        })
                    }else{

                    }
                });

            },
            reWrite(form){
                this.form = {};
                this.initType();
                this.$refs[form].resetFields();
            },
            initType(){
                if(this.releaseType){
                    this.form.type = this.releaseType;
                    this.disabled = true;
                }else{
                    this.typeList = this.checkTypeList;
                    this.disabled = false;
                }
            }
        },
        mounted() {
            this.initType();
        }
    }
</script>

<style scoped>
    .secretaryTaskRelease .topCard {
        width: 95%;
        margin: 0 auto;
        height: 80px;
        position: relative;
        z-index: 10;
    }
    .secretaryTaskRelease .titleCard {
        height:100%;
        text-align: left;
        background: linear-gradient(60deg, #66aabb, #43a047);
        box-shadow: 0 12px 20px -10px rgba(76, 175, 80, .28), 0 4px 20px 0 rgba(0, 0, 0, .12), 0 7px 8px -5px rgba(76, 175, 80, .2);
    }
    .secretaryTaskRelease .release-title {
        color: white;
        font-size: 20px;
        margin-top:-5px;
    }
    .secretaryTaskRelease .release-title-detail {
        color: hsla(0,0%,100%,.62);
        margin-top: 6px;
        position: absolute;
        font-size: 14px;
    }
    .secretaryTaskRelease .release-icon {
        margin-left: 0px;
        position:relative;
        vertical-align: middle;
    }
    .secretaryTaskRelease .cardHeight {
        margin-top: -40px;
        min-height: 650px;
    }
    .secretaryTaskRelease .firstRow {
        margin: calc(100vw / 1920 * 80) 0 0 ;
    }
    .secretaryTaskRelease .release-form {
        text-align: left;
        margin-left: 1%;
        max-width: 800px;
    }
    .secretaryTaskRelease .save_btn{
        width:157px;
        height:38px;
        background:rgba(10,155,26,1);
        border-radius:4px;
    }
    .secretaryTaskRelease .reset_btn{
        width:157px;
        height:38px;
        background:rgba(184, 225, 188, 1);
        border:1px solid rgba(184, 225, 188, 1);
        border-radius:4px;
    }
    .btnReleave{
        border: 1px solid #55BD94;
        width:140px;
        background:rgba(85,189,148,1);
        border-radius:4px;
    }
    .btn_reset{
        width:140px;
        background:#E6A23C;
        border-radius:4px;
    }
</style>
<style>
    .secretaryTaskRelease .el-form-item__label {
        color: #aaa!important;
    }
    .secretaryTaskRelease .el-form-item--mini.el-form-item, .el-form-item--small.el-form-item {
        margin-bottom: 30px;
    }
</style>
